package com.chencong.online.function;

import com.chencong.online.bean.PageViewCountBean;
import org.apache.flink.streaming.api.functions.windowing.WindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

/**
 * @program: user-behavior-analysis-online
 * @ClassName PageViewCountWindowFunc
 * @description:将窗口内统计输出
 * @author: chencong
 * @create: 2021-12-23 11:09
 **/
public class PageCountWindowFunc implements WindowFunction<Long, PageViewCountBean, String, TimeWindow> {
    @Override
    public void apply(String url, TimeWindow window, Iterable<Long> input, Collector<PageViewCountBean> out) throws Exception {
        long start = window.getStart();
        long end = window.getEnd();

        out.collect(new PageViewCountBean(start,end,url,input.iterator().next()));
    }
}
